/**
 * 登录页api
 */
import { request } from '@/utils/request'
import type { User } from '@/types/login'
// 1. 通过范型参数指定api返回数据类型
// export const loginByPassword = (formData: { mobile: string; password: string }) => {
//   return request.post<any, User>('/login/password', formData)
// }
// 2. 通过函数返回值指定api返回数据类型
export const loginByPassword = (formData: { mobile: string; password: string }): Promise<User> => {
  //  返回Promise
  return request.post('/login/password', formData)
}

/**
 *
 * @param mobile 手机
 * @param type 验证码类型： 'login' 登录 | 'register' 注册
 * @returns
 */
export const sendMobileCode = (mobile: string, type: 'login' | 'register') =>
  request.get<any, { code: string }>('/code', { params: { mobile, type } })

// 短信登录
export const loginByMobile = (mobile: string, code: string) =>
  request.post<any, User>('/login', { mobile, code })
